/// @tags: PersistedSegmentTree
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#define rint register int

using std::cin;
using std::cout;

namespace BlueQuantum {

typedef long long LL;

constexpr int MAXN = 3e5 + 3, SEGN = MAXN * 22;

int n, m, dep[MAXN], siz[MAXN], dfn[MAXN], dcnt, rt[MAXN];
std::vector<int> e[MAXN];
int segcnt;
int son[SEGN][2];
LL sum[SEGN];

inline void pushup(int x) { sum[x] = sum[son[x][0]] + sum[son[x][1]]; }

void build(int &x, int l, int r) {
  x = ++segcnt;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(son[x][0], l, mid);
  build(son[x][1], mid + 1, r);
}

void add(int &x, int y, int l, int r, int pos, int val) {
  x = ++segcnt;
  son[x][0] = son[y][0];
  son[x][1] = son[y][1];
  if (l == r) {
    sum[x] = sum[y];
    sum[x] += val;
    return;
  }
  int mid = (l + r) >> 1;
  pos <= mid ? add(son[x][0], son[y][0], l, mid, pos, val)
             : add(son[x][1], son[y][1], mid + 1, r, pos, val);
  pushup(x);
}

LL query(int x, int y, int l, int r, int L, int R) {
  if (L <= l && r <= R) return sum[x] - sum[y];
  int mid = (l + r) >> 1;
  LL ans = 0;
  if (L <= mid) ans = query(son[x][0], son[y][0], l, mid, L, R);
  if (mid < R) ans += query(son[x][1], son[y][1], mid + 1, r, L, R);
  return ans;
}

void dfs1(int u) {
  dfn[u] = ++dcnt;
  siz[u] = 1;
  for (auto v : e[u])
    if (dep[v] == 0) {
      dep[v] = dep[u] + 1;
      dfs1(v);
      siz[u] += siz[v];
    }
}

void dfs2(int u) {
  add(rt[dfn[u]], rt[dfn[u] - 1], 1, n, dep[u], siz[u] - 1);
  for (auto v : e[u])
    if (dep[v] > dep[u]) dfs2(v);
}

inline int main() {
  cin >> n >> m;
  for (rint i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  build(rt[0], 1, n);
  dep[1] = 1;
  dfs1(1);
  dfs2(1);
  for (int i = 1; i <= m; ++i) {
    int p, k;
    cin >> p >> k;
    LL ans = query(rt[dfn[p] + siz[p] - 1], rt[dfn[p] - 1], 1, n, dep[p] + 1, dep[p] + k);
    ans += (LL)std::min(k, dep[p] - 1) * (siz[p] - 1);
    cout << ans << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P3899 [湖南集训] 谈笑风生.in", "r", stdin);
  freopen("P3899 [湖南集训] 谈笑风生.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
